<template>
  <div class="ChildPage TablePage" v-loading="loading">
    <vb-page ref="page">
      <template #headerSearch-append="scope">
        <div>
          <span style="font-size: 12px; padding-right: 4px; color: #666666">物料</span>
          <el-select filterable remote :remote-method="e => getMaterialList(e)" v-model="scope.searchForm.materialNo" size="small" clearable class="material" placeholder="请输入物料编码或者名称" style="margin-right: 10px">
            <el-option v-for="item in materialList" :key="item.fNumber" :label="item.fNumber + '：' + item.fName + ' ' + item.fSpecification" :value="item.fNumber" />
          </el-select>
        </div>

      </template>

      <template #headerSearch-btn-append="{ searchForm }">
        <el-button type="warning" size="small" icon="el-icon-download" @click="doDownload(searchForm)">导出物料台帐报表</el-button>
      </template>
      <template #table-handle-edit="scope">
        <el-button type="text" :icon="el-icon-edit" @click="gotoDetail(scope.row.billNo)">查看</el-button>
      </template>
    </vb-page>
  </div>
</template>

<script>
export default {
  data() {
    return {
      materialLoading: false,
      dataLiat:[],
      materialList: [],
    }
  },
  async mounted() {
    await this.getStock()
    await this.selectStock()
  },
  methods : {
    gotoDetail(billNo = '') {
      let url = '/produce/prdColDetail'
      if (billNo) {
        url += `?billNo=${ billNo }`
      }
      this.$router.push(url)
    },
    async selectStock() {
      this.loading = true
      try {
        let res = await this.callApi('get_stock')
        if (!res.res) return
        this.dataList = res.data
      } finally {
        this.loading = false
      }
    },
    async doDownload(searchForm) {
      this.loading = true
      try {
        let res = await this.callApi('download_prdCol_part_bill', searchForm)
        if (!res.res) return
      } finally {
        this.loading = false
      }
    },
    async getMaterialList(val) {
      if (!val) {
        this.materialList = []
        return
      }
      this.materialLoading = true
      try {
        const res = await this.callApi('get_material_by_key', { key: val, pageSize: 20 })
        if (!res.res) return
        this.materialList = res.data
      } finally {
        this.materialLoading = false
      }
    }
  }
}
</script>

<style scoped>
</style>